<?php
if(!defined("YUEXUAN_REAL_ROOT_PATH")){
	exit("Access Denied.");
}

/**
 * 数据库连接
 * @author tongjun
 *
 */
class ext_dbHandle {
	public static $masterDbServer = "master";
	public static $slaveDbServer = "slave";
	
	private $_db;
	private $_dbs;
    private static $_instance;
    
    private function __construct() {
        // 连接数据库
    	$this->_db = new ext_mysql();
		$this->_db->connect (
			MYSQL_HOST.":".MYSQL_PORT, 
			MYSQL_USER, 
			MYSQL_PASS, 
			MYSQL_DB, 
			0, 
			true, 
			"utf8"
		);
    	$this->_dbs = new ext_mysql();
		$this->_dbs->connect (
			MYSQL_HOST_S.":".MYSQL_PORT_S, 
			MYSQL_USER_S, 
			MYSQL_PASS_S, 
			MYSQL_DB_S, 
			0, 
			true, 
			"utf8"
		);
    }
    private function __clone() {
    	
    }
    /**
     * 单例模式下取得数据库连接
     * @param in $no
     * @return ext_mysql
     */
    public static function getDb($dbServer="master") {
        if( ! (self::$_instance instanceof self) ) {
            self::$_instance = new self();
        }
        return ($dbServer==ext_dbHandle::$masterDbServer)?self::$_instance->_db:self::$_instance->_dbs;
    }
}
